package com.zhyt.intelligentpipeline.exception;

import lombok.*;

@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class CommonErrorDTO {
    private Integer code;

    private String msg;


    /**
     * 由ErrorCode构造生成CommonErrorDTO实例
     *
     * @param errorCode
     * @return
     */
    public static CommonErrorDTO of(ErrorBody errorBody) {
        return CommonErrorDTO.builder()
                .code(errorBody.getCode())
                .msg(errorBody.getMsg())
                .build();
    }

    /**
     * 由CommonException构造生成CommonErrorDTO实例
     * @param e
     * @return
     */
    public static CommonErrorDTO of(CustomException e) {
        return CommonErrorDTO.builder()
                .code(e.getErrorBody().getCode())
                .msg(e.getErrorBody().getMsg())
                .build();
    }
}
